package com.gx.babytun.controller;

import com.gx.babytun.utils.MailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.mail.MessagingException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class SendEmailController {

    @RequestMapping("/sendEmail")
    @ResponseBody
    public Map sendEmail(String name,String email,String title,String context) throws GeneralSecurityException, MessagingException, IOException {
        Map map = new HashMap();
        try {
            StringBuffer sb = new StringBuffer();
            sb.append("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            sb.append("<html xmlns='http://www.w3.org/1999/xhtml'>");
            sb.append("<head>");
            sb.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />");
            sb.append("<title>简历邮件</title>");
            sb.append("</head>");
            sb.append("<body>");
            sb.append("<p>姓名："+name+"</p>");
            sb.append("<p>Email："+email+"</p>");
            sb.append("<p>主题："+title+"</p>");
            sb.append("<p>内容："+context+"</p>");
            sb.append("</body>");
            sb.append("</html>");
            //调用邮件发送
            MailSender sms = new MailSender();
            sms.send_email("1142286199@qq.com", sb.toString(), "个人简历邮件发送");
            map.put("info", "ok");
        }catch (Exception e){
            map.put("info", "no");
        }
        return map;
    }
}
